package org.example.controller;

import org.example.entity.DistrictEntity;
import org.example.service.IDistrictService;
import org.example.util.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author hanjiafeng
 * @date 2021/4/20 15:16
 * @desc todo
 */
@Controller
@RequestMapping("district")
public class DistrictController {

    private final IDistrictService districtService;

    public DistrictController(IDistrictService districtService) {
        this.districtService = districtService;
    }

    @GetMapping("list")
    @ResponseBody
    public ResponseEntity<List<DistrictEntity>> list(String parent) {
        ResponseEntity<List<DistrictEntity>> responseEntity;
        List<DistrictEntity> districtEntityList = districtService.listByParent(parent);
        responseEntity = ResponseEntity.success("查询行政区划成功");
        responseEntity.setData(districtEntityList);
        return responseEntity;
    }
}
